package ch.fhnw.qualiscan.api;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.core.UriBuilder;

import ch.fhnw.qualiscan.api.output.LinkOutput;

public class Linker {

	public static List<LinkOutput> getBestPracticesLinks(int start, int size, String sort, String sortType, String universities, String surveys, String domains, String users, UriBuilder absolutePath, int bPSize) {
        UriBuilder builder = absolutePath;
        builder.queryParam("start", "{start}");
        builder.queryParam("size", "{size}");
        builder.queryParam("surveys", "{surveys}");
        builder.queryParam("sort", "{sort}");
        builder.queryParam("sortType", "{sortType}");
        builder.queryParam("universities", "{universities}");
        builder.queryParam("domains", "{domains}");
        builder.queryParam("users", "{users}");
        
        List<LinkOutput> links = new ArrayList<LinkOutput>();

        URI previousUri = null;
        if (start > 0) {
            int previous = start - size;
            if (previous < 0) {
                previous = 0;
            }
            previousUri = builder.clone().build(previous, size, surveys, sort, sortType, universities, domains, users);
            links.add(new LinkOutput("prev", previousUri + ""));
        }

        URI nextUri = null;
        if (bPSize == size) {
            int next = start + size;
            nextUri = builder.clone().build(next, size, size, surveys, sort, sortType, universities, domains, users);
            links.add(new LinkOutput("next", nextUri + ""));
        }

        return links;
    }
	
}
